package com.nanfang51g3.ckz.ui.update.password;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.nanfang51g3.ckz.R;
import com.nanfang51g3.ckz.application.CkzApplication;
import com.nanfang51g3.ckz.ui.base.IPresenter;
import com.nanfang51g3.ckz.ui.base.Base2Activity;
import com.nanfang51g3.ckz.ui.home.HomeMainActivity;
import com.nanfang51g3.ckz.utils.AppManager;
import com.nanfang51g3.ckz.utils.ButtonUtils;
import com.nanfang51g3.ckz.utils.EasyToast;
import com.nanfang51g3.ckz.utils.KLog;
import com.nanfang51g3.ckz.widget.ClearEditText;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/4/19.
 */
public class UpPasswordActivity extends Base2Activity implements UpPasswordContract.View {
    UpPasswordContract.UpPasswordActionsListener upPasswordActionsListener;
    @Bind(R.id.index_tv_right_title)
    TextView indexTvRightTitle;
    @Bind(R.id.cet_up_password_old)
    ClearEditText cetUpPasswordOld;
    @Bind(R.id.cet_up_password_new)
    ClearEditText cetUpPasswordNew;
    @Bind(R.id.cet_up_password_confirm)
    ClearEditText cetUpPasswordConfirm;
    @Override
    public IPresenter getPresenter() {
        return null;
    }

    @Override
    public int getContentView() {
        return R.layout.up_password;
    }

    @Override
    public boolean isShowLeftIcon() {
        return true;
    }

    @Override
    public boolean isShowRightIcon() {
        return false;
    }

    @Override
    public int setLeftIcon() {
        return R.mipmap.ic_accounting_left;
    }

    @Override
    public int setRightIcon() {
        return 0;
    }

    @Override
    public int showTitle() {
        return R.string.str_up_password;
    }

    @Override
    public void onClickLeft(View v) {
        AppManager.getAppManager().finishActivity(this);
    }

    @Override
    public void onClickRight(View v) {

    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    public void exitLogin() {
        AppManager.getAppManager().finishAllActivity();
        startActivity(new Intent(UpPasswordActivity.this, HomeMainActivity.class));

    }

    @Override
    public void showMessage(String message) {
        EasyToast.showShort(this, message);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        upPasswordActionsListener = DaggerUpPasswordContractComponent
                .builder()
                .appComponent(CkzApplication.getAppComponent())
                .upPasswordPresenterModule(new UpPasswordPresenterModule(this))
                .build().getUpPasswordPresenter();
        KLog.i("TAG", upPasswordActionsListener == null ? "upPasswordActionsListener==null" : "upPasswordActionsListener!=null");
        ButterKnife.bind(this);

        indexTvRightTitle.setVisibility(View.VISIBLE);
        indexTvRightTitle.setText(R.string.str_save);


    }
    @OnClick(R.id.index_tv_right_title)
    public void index_tv_right_title(View view) {
        if (!ButtonUtils.isFastDoubleClick(R.id.index_tv_right_title)) {
            String oldpass = cetUpPasswordOld.getText().toString().trim();
            String newPassword = cetUpPasswordNew.getText().toString().trim();
            String confirmPassword = cetUpPasswordConfirm.getText().toString().trim();
            /**
             * @see  UpPasswordPresenter#updatePassword(String, String, String)
             */
            upPasswordActionsListener.updatePassword(oldpass, newPassword, confirmPassword);
        }

    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);//解除绑定，官方文档只对fragment做了解绑

    }
}
